package com.second.app.thread.threadlocal.tools;

/**
 * @author gyz
 * @date 2021/1/29 15:18
 * 定义一个ThreadLocal，存储每个线程私有变量值
 */
public class Main {
    public static void main(String[] args) {
        try {
            SonTheadA sonTheadA = new SonTheadA();
            SonTheadB sonTheadB = new SonTheadB();
            sonTheadA.start();
            sonTheadB.start();
            int value = (int) (Math.random() * 1000);
            Tool.t1.set(value + "");
            System.out.println(Thread.currentThread().getName() + "存入值：" + value);
            Thread.sleep(2000);
            System.out.println(Thread.currentThread().getName() + "获取：" + Tool.t1.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
